package Servlet.Teacher;

import Service.Teacher.CheckDataService;
import Service.Teacher.Imp.CheckDataServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by IntelliJ IDEA.
 * Author: Deng PengFei
 * Date: 2021/8/27
 * Time: 8:49
 */

@WebServlet(urlPatterns = {"/checkData"},name = "CheckServlet")
public class CheckServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String url = request.getRequestURI();
        if ("/checkData".equals(url)) {
            checkData(request, response);
        }

    }

    private void checkData(HttpServletRequest request, HttpServletResponse response) throws IOException {
        CheckDataService checkDataService = new CheckDataServiceImp();
        String result = request.getParameter("result"); //审核结果
        String key = request.getParameter("key"); //审核的数据的关键字
        String opinion = request.getParameter("opinion"); //审核意见
        String type = request.getParameter("type");  //审核的阶段
        String bh = request.getParameter("bh"); //论文的编号
        String TNO = request.getParameter("userName");
        boolean flag = false;
        switch (type) {
            case "任务书":
                flag = checkDataService.checkAss(result, opinion, key, bh);
                break;
            case "开题报告":
                flag = checkDataService.checkReport(result, opinion, key, bh);
                break;
            case "中期检查":
                flag = checkDataService.updateMedium(result, opinion, key, bh, TNO);
                break;
            case "初稿":
                flag = checkDataService.checkFirst(result, opinion, key, bh, "初稿", "定稿");
                break;
            case "定稿":
                flag = checkDataService.checkFirst(result, opinion, key, bh, "定稿", "定稿评分");
                break;
            case "终稿":
                flag = checkDataService.checkFirst(result, opinion, key, bh, "终稿", "完成");
                break;
            default:
                break;
        }
        PrintWriter out = response.getWriter();
        out.print(flag);
        out.close();
    }
}
